package com.ruoyi.project.system.service.impl;

import com.ruoyi.project.system.domain.TempWeekDaily;
import com.ruoyi.project.system.mapper.TempWeekDailyMapper;
import com.ruoyi.project.system.service.ITempWeekDailyService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;


@Service
public class TempWeekDailyServiceImpl implements ITempWeekDailyService {

    @Autowired
    private TempWeekDailyMapper tempWeekDailyMapper;

    @Override
    public List<TempWeekDaily> selectByDeptAndDate(String department, String date) {
        return tempWeekDailyMapper.selectByDeptAndDate(department, date);
    }

    @Override
    public List<TempWeekDaily> selectByDate(String date) {
        return tempWeekDailyMapper.selectByDate(date);
    }

    @Override
    @Transactional
    public int batchInsert(List<TempWeekDaily> list) {
        if (list == null || list.isEmpty()) return 0;
        tempWeekDailyMapper.batchInsert(list);
        return list.size();
    }

    @Override
    @Transactional
    public void truncateTable() {
        tempWeekDailyMapper.truncateTable();
    }

    @Override
    public boolean decreaseRemaining(Long doctorId, String date) {
        // 调用 Mapper 执行扣减 SQL，影响行数>0 表示成功
        int affectedRows = tempWeekDailyMapper.decreaseRemaining(doctorId, date);
        return affectedRows > 0;
    }
}